package com.xxcloud.web.folder.controller;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xxcloud.model.exception.folder.FolderException;
import com.xxcloud.model.web.JsonResult;
import com.xxcloud.model.web.ListResult;
import com.xxcloud.model.web.folder.dto.FolderDTO;
import com.xxcloud.model.web.folder.vo.FolderVO;
import com.xxcloud.service.folder.IFolderService;
import com.xxcloud.web.base.controller.BaseController;
import io.swagger.annotations.ApiOperation;

/**
 * Created by chenbingwen on 19/10/28.
 */
@RestController
@RequestMapping("folder")
public class FolderController extends BaseController {

    @Resource(name = "folderService")
    private IFolderService folderService;

    @ApiOperation(value = "文件夹列表", notes = "文件夹层级关系")
    @GetMapping("folders.json")
    public JsonResult folders() {
        ListResult<FolderVO> result = folderService.listFolderVO();
        return JsonResult.getResult(result);
    }

    @ApiOperation(value = "新增/修改文件夹", notes = "新增或修改文件夹")
    @PostMapping("folder.json")
    public JsonResult folder(@RequestBody FolderDTO dto) throws FolderException {
        long operatorId = getUserId();
        boolean result = folderService.upsertFolder(operatorId, dto);
        return JsonResult.getResult(result);
    }

}